import { pushScopeId } from "vue";
import { createRouter, createWebHashHistory } from "vue-router";
import { isLogin } from "../uitils/Token";
const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: "/",
      name: "home",
      component: () => import("../page/home.vue"),
    },
    {
      path: "/",
      redirect: "/home", //跳转位置
    },
    {
      path: "/list",
      name: "list",
      component: () => import("../page/list.vue"),
    },
    {
      path: "/news",
      name: "news",
      component: () => import("../page/news.vue"),
    },
    {
      path: "/cart",
      name: "cart",
      component: () => import("../page/cart.vue"),
      meta: {
        isLogined: true,
      },
    },
    {
      path: "/user",
      name: "user",
      component: () => import("../page/user.vue"),
      meta: { isLogined: true },
    },
    {
      path: "/login",
      name: "login",
      component: () => import("../page/mermber/login.vue"),
      meta: {
        isTabared: true,
      },
    },
    {
      path: "/enter",
      name: "enter",
      component: () => import("../page/mermber/enter.vue"),
      meta: {
        isTabared: true,
      },
      path:'/item',
      name:"item",
      component:()=>import("../page/mermber/item.vue"),
      meta:{
        isTabared:true
      }
    },
    {
      path:'/enter',
      name:"enter",
      component:()=>import("../page/mermber/enter.vue"),
      meta:{
        isTabared:true
      }
    },
    {
      path: "/changeInfo",
      name: "changeInfo",
      component: () => import("../page/mermber/changeInfo.vue"),
      meta: {
        isTabared: true,
      },
    },
    {
      path: "/nicheng",
      name: "nicheng",
      component: () => import("../page/mermber/nicheng.vue"),
      meta: {
        isTabared: true,
      },
    },

    {
      path: "/changpassword",
      name: "changpassword",
      component: () => import("../page/mermber/changpassword.vue"),
      meta: {
        isTabared: true,
      },
    },
    {
      path: "/search",
      name: "search",
      component: () => import("../page/mermber/search.vue"),
      meta: {
        isTabared: true,
      },
    },
    {
      path:'/touxiang',
      name:"touxiang",
      component:()=>import("../page/mermber/touxiang.vue"),
      meta:{
        isTabared:true
      }
    }
    
  ]
})
// 全局守卫 跳转之前执行
router.beforeEach((to, from, next) => {
  if (to.meta.isLogined) {
    // 根据本地存储判断有没有登陆过
    if (isLogin()) {
      next();
    } else {
      next({
        name: "login",
      });
    }
  } else {
    next();
  }
});
export default router;
